package com.newtouch.bxzs.business.train.controller;

import com.newtouch.bxzs.business.config.MyLog;
import com.newtouch.bxzs.business.train.model.bo.KnowledgeCardAppBO;
import com.newtouch.bxzs.business.train.model.bo.KnowledgeCardBO;
import com.newtouch.bxzs.business.train.model.vo.KnowledgeCardAppVO;
import com.newtouch.bxzs.business.train.model.vo.NewKnowledgeCardVO;
import com.newtouch.bxzs.business.train.service.KnowledgeCardService;
import com.newtouch.bxzs.common.base.response.BaseResponse;
import com.newtouch.bxzs.common.base.response.RespGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 知识卡片控制器
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/6 13:33</td>
 * <td>lingshouyi</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author lingshouyi
 * @version 1.0.0
 * @since 1.0.0
 */
@Api(tags = "知识卡片")
@RestController
@RequestMapping("/knowledgeCardController")
@SuppressWarnings("unchecked")
public class KnowledgeCardController {

	@Autowired
	private KnowledgeCardService knowledgeCardService;

	/**
	 * 静态变量：系统日志
	 */
	private static final Log logger = LogFactory.getLog(KnowledgeCardController.class);

	@ApiOperation(value = "APP端查看知识卡片通知信息", notes = "查看知识卡片通知信息")
	@GetMapping("/getKnowledgeCardNoticeList")
	@MyLog(systemFunctionName = "知识卡片", systemFunctionUrl = "/knowledgeCardController/getKnowledgeCardNoticeList", userOperationType = 4, userOperationSummary = "APP端查看知识卡片通知信息")
	public BaseResponse<KnowledgeCardAppBO> getKnowledgeCardNoticeList() {
		logger.info("查看知识卡片通知信息");
		return RespGenerator.returnOK(knowledgeCardService.getKnowledgeCardNoticeList());
	}

	@ApiOperation(value = "PC端查询知识卡片列表信息", notes = "查询所有知识卡片列表信息")
	@PostMapping("/getKnowledgeCardList")
	@MyLog(systemFunctionName = "知识卡片", systemFunctionUrl = "/knowledgeCardController/getKnowledgeCardList", userOperationType = 4, userOperationSummary = "PC端查询知识卡片列表信息")
	public BaseResponse<KnowledgeCardBO> getKnowledgeCardList(@RequestBody KnowledgeCardAppVO knowledgeCardVO) {
		logger.info("PC端查询知识卡片列表信息");
		return RespGenerator.returnOK(knowledgeCardService.getKnowledgeCardList(knowledgeCardVO, false));
	}

	@ApiOperation(value = "APP端查询知识卡片列表信息", notes = "查询所有知识卡片列表信息")
	@PostMapping("/getKnowledgeCardListOnApp")
	@MyLog(systemFunctionName = "知识卡片", systemFunctionUrl = "/knowledgeCardController/getKnowledgeCardListOnApp", userOperationType = 4, userOperationSummary = "APP端查询知识卡片列表信息")
	public BaseResponse<KnowledgeCardBO> getKnowledgeCardListOnApp(@RequestBody KnowledgeCardAppVO knowledgeCardVO) {
		logger.info("APP端查询知识卡片列表信息");
		return RespGenerator.returnOK(knowledgeCardService.getKnowledgeCardList(knowledgeCardVO, true));
	}

	@ApiOperation(value = "查看知识卡片详情信息", notes = "根据知识卡片编号查看知识卡片详情信息")
	@GetMapping("/getKnowledgeCardDetail")
	@MyLog(systemFunctionName = "知识卡片", systemFunctionUrl = "/knowledgeCardController/getKnowledgeCardDetail", userOperationType = 4, userOperationSummary = "查看知识卡片详情信息")
	public BaseResponse<KnowledgeCardAppBO> getKnowledgeCardDetail(
			@RequestParam(value = "knowledgeCardId") @ApiParam(value = "知识卡片ID") String knowledgeCardId) {
		logger.info("查看知识卡片详情信息");
		return RespGenerator.returnOK(knowledgeCardService.getKnowledgeCardDetail(knowledgeCardId));
	}

	@ApiOperation(value = "新增或者修改知识卡片信息", notes = "新增或者修改知识卡片信息")
	@PostMapping("/modifyKnowledgeCard")
	@MyLog(systemFunctionName = "知识卡片", systemFunctionUrl = "/knowledgeCardController/modifyKnowledgeCard", userOperationType = 5, userOperationSummary = "新增或者修改知识卡片信息")
	public BaseResponse<String> modifyKnowledgeCard(@RequestBody NewKnowledgeCardVO newKnowledgeCardVO) {
		return RespGenerator.returnOK(knowledgeCardService.modifyKnowledgeCard(newKnowledgeCardVO));
	}

	@ApiOperation(value = "发布/撤销知识卡片", notes = "发布/撤销知识卡片")
	@GetMapping("/changeKnowledgeCardState")
	@MyLog(systemFunctionName = "知识卡片", systemFunctionUrl = "/knowledgeCardController/changeKnowledgeCardState", userOperationType = 2, userOperationSummary = "发布/撤销知识卡片")
	public BaseResponse<Integer> changeKnowledgeCardState(
			@RequestParam(value = "knowledgeCardId") @ApiParam(value = "知识卡片ID") String knowledgeCardId,
			@RequestParam(value = "publishStatus") @ApiParam(value = "发布状态：1-未发布；2-已发布；3-已结束；4-已取消；5-已撤销") String publishStatus) {
		return RespGenerator.returnOK(knowledgeCardService.changeKnowledgeCardState(knowledgeCardId, publishStatus));
	}

	@ApiOperation(value = "删除/批量删除知识卡片信息")
	@PostMapping("/deleteKnowledgeCard")
	@MyLog(systemFunctionName = "知识卡片", systemFunctionUrl = "/knowledgeCardController/deleteKnowledgeCard", userOperationType = 3, userOperationSummary = "删除/批量删除知识卡片信息")
	public BaseResponse<Integer> deleteKnowledgeCard(
			@RequestBody @ApiParam(value = "知识卡片ID编号", required = true) List<String> knowledgeCardIds) {
		logger.info("删除/批量删除知识卡片信息");
		return RespGenerator.returnOK(knowledgeCardService.deleteKnowledgeCard(knowledgeCardIds));
	}
}
